package com.ocom.accesservice.controller;

import com.github.pagehelper.PageInfo;
import com.ocom.accesservice.service.GroupPerService;
import com.ocom.common.constant.AccessServiceUrl;
import com.ocom.common.entity.access.EntityMjGroupPer;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.request.access.GetGroupPerReq;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
public class GroupPerController {
    private final Logger log = LoggerFactory.getLogger(GroupPerController.class);


    @Autowired
    private  GroupPerService groupPerService;


    @PostMapping(AccessServiceUrl.URL_AccessRemoveWhiteUser)
    public Result removeWhiteUser(Long companyId,Long pId){
        groupPerService.removeWhiteUser(companyId,pId);
        return ResultUtil.success();
    }

    @PostMapping(AccessServiceUrl.URL_AccessGetWhiteUser)
    public Result getWhiteUser(Long companyId,Long pId){
        List<EntityMjGroupPer> list= groupPerService.getList(companyId,pId);
        if(list == null || list.size()<=0){
            return ResultUtil.error(ResultEnum.Err_4017);
        }
        return ResultUtil.success(list);
    }


    @PostMapping(AccessServiceUrl.Url_getGroupPerList)
    public Result<PageInfo<EntityMjGroupPer>> getGroupPerList(@RequestBody GetGroupPerReq req){
        PageInfo<EntityMjGroupPer> list= groupPerService.getGroupPerList(req.getComId(),req);
        return ResultUtil.success(list);
    }




}
